package com.itheima.tlias84.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.tlias84.config.StudentConfig;
import com.itheima.tlias84.utils.ResultUtil;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("yml")
public class TestReadYmlController {

//    @Value("${student.name}")
//    String name;
//    @Value("${student.age}")
//    Integer age;
//    @Value("${student.subject}")
//    String[] subject;
    @Resource
    StudentConfig studentConfig;

    @Resource
    Environment env;

    @GetMapping
    public ResultUtil readCustomConfigByYml(){

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name",studentConfig.getName());
        jsonObject.put("age",studentConfig.getAge());
        jsonObject.put("科目", Arrays.toString(studentConfig.getSubject()));
        jsonObject.put("老师",studentConfig.getTeachers());
        jsonObject.put("家庭成员",studentConfig.getFamily());
        String[] activeProfiles = env.getActiveProfiles();
        jsonObject.put("active",activeProfiles);
        String property = env.getProperty("server.port");
        jsonObject.put("port",property);
        return ResultUtil.success(jsonObject);
    }
}
